﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Sale_Operation;
using Sale_Common;
using Sale_Model;
using SaleSystem;
using ExtAspNet;

namespace SaleSystem.Fina
{
    public partial class frm_AccountEdit : PageBase
    {
        #region Page Event
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                InitControl();
                BindDropDownList();
               
                GetAndBind();
            }
        }
        protected void bnSave_Click(object sender, EventArgs e)
        {
           
            SModel.CreateMan = LinkService.GetCurrentUser().SUser_Id;
            SModel.CreateTime = System.DateTime.Now;
            SModel.AList_Id = Id;
            SModel.AList_BData_Id = ValueHandler.GetIntNumberValue(this.ddl_AList_BData_Id.SelectedValue);
            SModel.AList_Money = ValueHandler.GetDecNumberValue(this.nb_AList_Money.Text);
            SModel.AList_Name = this.tb_AList_Name.Text;
            SModel.AList_UserName = this.tb_AList_UserName.Text;
            SModel.State = 1; 
            bool blHasExists = Manager.HasExists(SModel);
            if (blHasExists)
            {
                ExtAspNet.Alert.Show("该账户已经存在，请重新输入！", MessageBoxIcon.Information);
            }
            else
            {
                bool blRes = Manager.Save(SModel);
                if (blRes)
                {
                    //ExtAspNet.PageContext.RegisterStartupScript("parent.__doPostBack('','"+LinkService.RefreshString+"')");
                    // ExtAspNet.PageContext.RegisterStartupScript(ExtAspNet.ActiveWindow.
                    //ExtAspNet.Alert.Show("OK","OK", ExtAspNet.ActiveWindow.GetHidePostBackReference(LinkService.RefreshString));
                    ExtAspNet.PageContext.RegisterStartupScript(ExtAspNet.ActiveWindow.GetHidePostBackReference(LinkService.RefreshString));

                }
                else
                    ExtAspNet.Alert.Show("账户编辑失败！", MessageBoxIcon.Error);
            }
        } 
            
        #endregion

        #region Method
        private void InitControl()
        {
            bnClose.OnClientClick = ExtAspNet.ActiveWindow.GetHideReference();
            if (Request["Id"] != null)
            {
                Id = ValueHandler.GetIntNumberValue(Request["Id"]);
            }

        }
        private void BindDropDownList()
        {
            BaseDataOp BaseManager = new BaseDataOp();

            DataTable dtType = BaseManager.GetList("BData_Type=5");
            ddl_AList_BData_Id.DataSource = dtType;
            ddl_AList_BData_Id.DataBind();
            ddl_AList_BData_Id.Items.Insert(0, new ExtAspNet.ListItem("-未选择-", "-1"));
        }
        private void GetAndBind()
        {
            if (Id != 0)
            {
                SModel.AList_Id = Id;
                SModel = Manager.GetModel(SModel) as AccountList;
                this.tb_AList_Name.Text = SModel.AList_Name;
                this.tb_AList_UserName.Text = SModel.AList_UserName;
                this.ddl_AList_BData_Id.SelectedValue = SModel.AList_BData_Id.ToString();
                this.nb_AList_Money.Text = SModel.AList_Money.ToString();
            }
        }
        #endregion

        #region Property
        AccountListOp Manager = new AccountListOp();
        new Sale_Model.AccountList SModel = new Sale_Model.AccountList();
        #endregion

    }
}
